var TimeOut_ = null;
TimeOut_ = setTimeout(time,1000);
function str0(a)
{
    if(a<10) return "0";
    else return "";
}
function time()
{
    clearTimeout(TimeOut_);
    var dt = new Date();
    var year = dt.getFullYear();
    var month = dt.getMonth() + 1;
    var day = dt.getDate();
    var hour = dt.getHours();
    var minute = dt.getMinutes();
    var sec = dt.getSeconds();
    if(sec < 10)
    var ts = "现在的时间为："+year+"年"+month+"月"+day+"日"+hour+"时"+minute+"分"+sec+"秒";
    document.getElementById("nowdate").innerHTML = year+"-"+str0(month)+month+"-"+str0(day)+day+" "+str0(hour)+hour+":"+str0(minute)+minute+":"+str0(sec)+sec;
    TimeOut_ = setTimeout(time,1000);              
}
function vify_id()
{
  var x=document.getElementById("user_id").value;
  
  if(x.length<=3)
  {
     document.getElementById("user_id_info").innerHTML="<font color=red>帐号长度不短于3个字符</font>";
     return false;
  }
  else
  {
	  var myreg =  /^[a-zA-Z0-9_]{1,}$/; 
	  if (!myreg.test(x)) 
		{
		    document.getElementById("user_id_info").innerHTML="<font color=red>帐号只能由字母、数字、下划线组成</font>";
			return false;
		}
     document.getElementById("user_id_info").innerHTML="<font color=red></font>";
     
     return true;
  }
}
function vify_email() 
{
    var temp = document.getElementById("user_email");
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if (!myreg.test(temp.value)) 
    {
        document.getElementById("user_email_info").innerHTML="<font color=red>电子邮箱格式不正确</font>";
        return false;
    }
    else
    {
        document.getElementById("user_email_info").innerHTML="<font color=red></font>";
        return true;
    }
}
function vify_school() 
{
    var temp = document.getElementById("user_school");
    var myreg = /^[\u4E00-\u9FA5]+$/;
    if (!myreg.test(temp.value)) 
    {
        document.getElementById("user_school_info").innerHTML="<font color=red>请输入学校中文全称</font>";
        return false;
    }
    else
    {
        document.getElementById("user_school_info").innerHTML="<font color=red></font>";
        return true;
    }
    	
}
 


function vify_password1(flag)
{
  var x=document.getElementById("user_password").value;
  if(flag == 0 || x.length > 0)
  {
	  if(x.length<6)
	  {
	     document.getElementById("user_password_info1").innerHTML="<font color=red>密码长度不短于6个字符</font>";
	     return false;
	  }
	  else
	  {
		  document.getElementById("user_password_info1").innerHTML="<font color=red></font>";
		  return true;
		  
	  }
  }
  return true;
}
function vify_password2(flag)
{
  var x=document.getElementById("user_password").value;
  var y=document.getElementById("rptpassword").value;
  if(flag == 0 || x.length > 0)
  {
	  if(x != y)
	  {
	     document.getElementById("user_password_info2").innerHTML="<font color=red>两次输入的密码不一致</font>";
	     return false;
	  }
	  else
	  {
		 document.getElementById("user_password_info2").innerHTML="<font color=red></font>";
		 return true;
	  }
  }
  return true;
}
function vify_opassword()
{
	var x=document.getElementById("opassword").value;
	if(x.length < 6)
	{
	     document.getElementById("opassword_info").innerHTML="<font color=red>原密码不能为空且不少于6个字符</font>";
		 return false;
	}
	else
	{
		document.getElementById("opassword_info").innerHTML="<font color=red></font>";
		return true;
	}
	return true;
}
function vify_userinfo()
{
	var xx = true;
	var if_exist = document.getElementById("user_id");
	if(if_exist)
	{
		xx = xx && vify_id();
		xx = xx && vify_password1(0);
		xx = xx && vify_password2(0);
	}
	else
	{
		xx = xx && vify_opassword();
	}
	xx = xx && vify_email();
	if(document.getElementById("user_school"))
		xx = xx && vify_school();
	if(xx == false)
	{
		alert("有不合法表项，请检查填写信息")
		return false;
	}
	return true;
}

function vify_card_num(card)
{
	    
    if (card.length != 15 && card.length != 18) {
        return (false);
    }
    
    var area = {
        11 : "北京",
        12 : "天津",
        13 : "河北",
        14 : "山西",
        15 : "内蒙古",
        21 : "辽宁",
        22 : "吉林",
        23 : "黑龙江",
        31 : "上海",
        32 : "江苏",
        33 : "浙江",
        34 : "安徽",
        35 : "福建",
        36 : "江西",
        37 : "山东",
        41 : "河南",
        42 : "湖北",
        43 : "湖南",
        44 : "广东",
        45 : "广西",
        46 : "海南",
        50 : "重庆",
        51 : "四川",
        52 : "贵州",
        53 : "云南",
        54 : "西藏",
        61 : "陕西",
        62 : "甘肃",
        63 : "青海",
        64 : "宁夏",
        65 : "新疆",
        71 : "台湾",
        81 : "香港",
        82 : "澳门",
        91 : "国外"
    };
    
    if (area[parseInt(card.substr(0, 2))] == null) {
        return (false);
    }
    
    if (card.length == 15) {
        pattern = /^\d{15}$/;
        if (pattern.exec(card) == null) {
            return (false);
        }
        var birth = parseInt("19" + card.substr(6, 2));
        var month = card.substr(8, 2);
        var day = parseInt(card.substr(10, 2));
        switch (month) {
        case '01':
        case '03':
        case '05':
        case '07':
        case '08':
        case '10':
        case '12':
            if (day > 31) {
                return false;
            }
            break;
        case '04':
        case '06':
        case '09':
        case '11':
            if (day > 30) {
                return false;
            }
            break;
        case '02':
            if ((birth % 4 == 0 && birth % 100 != 0) || birth % 400 == 0) {
                if (day > 29) {
                    return false;
                }
            } else {
                if (day > 28) {
                    return false;
                }
            }
            break;
        default:
            return false;
        }
        var nowYear = new Date().getYear();
        if (nowYear - parseInt(birth) < 15 || nowYear - parseInt(birth) > 100) {
            return false;
        }
        return (true);
    }
    
    var Wi = new Array(
            7, 9, 10, 5, 8, 4, 2, 1, 6,
            3, 7, 9, 10, 5, 8, 4, 2, 1);
    var lSum = 0;
    var nNum = 0;
    var nCheckSum = 0;
    
    for (i = 0; i < 17; ++i) {
        
        if (card.charAt(i) < '0' || card.charAt(i) > '9') {
            return (false);
        } else {
            nNum = card.charAt(i) - '0';
        }
        lSum += nNum * Wi[i];
    }
    
    if (card.charAt(17) == 'X' || card.charAt(17) == 'x') {
        lSum += 10 * Wi[17];
    } else if (card.charAt(17) < '0' || card.charAt(17) > '9') {
        return (false);
    } else {
        lSum += (card.charAt(17) - '0') * Wi[17];
    }
    
    if ((lSum % 11) == 1) {
        return true;
    } else {
        return (false);
    }

}
function vify_sf_card()
{
  var i, card;
  for(i = 0; i < 3; i ++)
  {
  	card=document.getElementById("stu_card" + i).value;
	if(!vify_card_num(card))
	{
		alert("队员 "+(i+1)+" 的身份证号 \""+card+"\" 不合法");
		document.getElementById("stu_card" + i).focus();
		return false;
  	}
  }
  return true;
}
function vify_rj_card()
{
  var card;
  	card=document.getElementById("stu_card").value;
	if(!vify_card_num(card))
	{
		alert("队员的身份证号 \""+card+"\" 不合法");
		document.getElementById("stu_card").focus();
		return false;
	}
  return true;
}

function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}